﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace BLL.Sys
{
    public class EnumItem
    {
        public static string Add(Model.Sys.EnumItem _obj)
        {
            return (new SQLServerDAL.Sys.EnumItem()).Add(_obj);
        }

        public static string Update(Model.Sys.EnumItem _obj)
        {
            return (new SQLServerDAL.Sys.EnumItem()).Update(_obj);
        }

        public static Model.Sys.EnumItem GetObjById(string enumDefId)
        {
            return (new SQLServerDAL.Sys.EnumItem()).GetObjById(enumDefId);
        }

        public static void Delete(string enumDefId)
        {
            (new SQLServerDAL.Sys.EnumItem()).Delete(enumDefId);
        }

        public static string GetValueByText(string enumKey, string enumText)
        {
            object _obj = BLL.Search.CommonSearch.ExecScalar("EnumItem",
                "TOP 1 EnumValue",
                new string[] { "EnumText", "EnumKey" },
                new string[] { "Equal", "Equal" },
                new string[] { "'" + enumText + "'", "'" + enumKey + "'" },
                null,
                null);

            if (_obj != null)
                return _obj.ToString();
            else
                return "0";
        }
        public static string GetTextByValue(string enumKey, string enumValue)
        {
            object _obj = BLL.Search.CommonSearch.ExecScalar("EnumItem",
                "TOP 1 EnumText",
                new string[] { "EnumValue", "EnumKey" },
                new string[] { "Equal", "Equal" },
                new string[] { "'" + enumValue + "'", "'" + enumKey + "'" },
                null,
                null);

            if (_obj != null)
                return _obj.ToString();
            else
                return "";
        }
        /// <summary>
        /// 获取中英文名称
        /// </summary>
        /// <param name="enumKey"></param>
        /// <param name="enumValue"></param>
        /// <returns></returns>
        public static string GetTextByValue_EN(string enumKey, string enumValue)
        {
            DataTable dat = BLL.Search.CommonSearch.ExecSelect("EnumItem",
                new string[] { "EnumText", "EnumEnText" },
                new string[] { "EnumValue", "EnumKey" },
                new string[] { "Equal", "Equal" },
                new string[] { "'" + enumValue + "'", "'" + enumKey + "'" },
                null,
                null);

            string res = "";
            if (dat != null && dat.Rows.Count > 0)
            {
                res = dat.Rows[0][1].ToString();
            }

            dat.Dispose();
            return res;
        }
    }
}
